<%--
  Created by IntelliJ IDEA.
  User: chen
  Date: 30/03/2018
  Time: 11:40 AM
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*, java.lang.String" contentType="text/html;charset=utf-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>登录成功</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

</head>

<body>
<p>登录成功as <%=request.getParameter("user")%>.</p>
<%
    PreparedStatement sql = null;
    ResultSet rs = null;
    Connection conn = null;
    String data = "";
    boolean table_exists = true;
%>
<%
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/resemblance";
    String use = request.getParameter("user");
    String password = "12345678c";
    Class.forName(driver);
    conn = DriverManager.getConnection(url, "root", password);
    sql = conn.prepareStatement("SELECT * FROM `" + use + "`");
    try {
        rs = sql.executeQuery();
    } catch (Exception e) {
        table_exists = false;
    }

    if (table_exists) {
        rs.last();
        int cols = rs.getRow();
%>
<table border="1">
    <tr>
        <td>编号</td>
        <%for (int i = 1; i <= cols; i++) {%>
        <td><%="Gl-" + i%>
        </td>
        <%}%>
    </tr>
    <%
        rs.beforeFirst();
        int count = 1;
        while (rs.next()) {
    %>
    <tr>
        <td><%="Gl-" + count%>
        </td>
        <%
            for (int i = 1; i <= cols; i++) {
                data = rs.getString("Gl-" + i);
        %>
        <td><%=data%>
        </td>
        <%}%>
    </tr>
    <%
            count++;
        }
    %>
</table>
<%}
else{
%><p>数据表不存在或为空</p><%
}%>
</body>
</html>